import winston from 'winston'
import {getAppHome} from './config'

const { combine, printf, timestamp } = winston.format

const customFormat = printf(({ level, message, timestamp }) => {
  return `${timestamp} ${level}: ${message}`
})

const logFormat = combine(timestamp(), customFormat);

const logger = winston.createLogger({
  level: 'info',
  format: logFormat,
  transports: [
    new winston.transports.File({
      filename: 'packages-truck.log',
      dirname: getAppHome()
    })
  ]
})

export const simpleLogger = winston.createLogger({
  level: 'info',
  format: printf((info) => info.message),
  transports: [
    new winston.transports.File({
      filename: 'packages-truck.log',
      dirname: getAppHome()
    })
  ]
})

// if (process.env.NODE_ENV !== 'production') {
//   logger.add(
//     new winston.transports.Console({
//       format: logFormat
//     })
//   )
// }

export default logger
